<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="生产领料_id" prop="scllId">
        <el-input
          v-model="queryParams.scllId"
          placeholder="请输入生产领料_id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="生产领料单编号" prop="requisitionNo">
        <el-input
          v-model="queryParams.requisitionNo"
          placeholder="请输入生产领料单编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="生产线" prop="productionLine">
        <el-input
          v-model="queryParams.productionLine"
          placeholder="请输入生产线"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="生产类型" prop="productionType">
        <el-select v-model="queryParams.productionType" placeholder="请选择生产类型" clearable>
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>
      <el-form-item label="生产订单编号" prop="productionOrderNo">
        <el-input
          v-model="queryParams.productionOrderNo"
          placeholder="请输入生产订单编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="订单日期" prop="orderDate">
        <el-date-picker clearable
          v-model="queryParams.orderDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择订单日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="客户" prop="customer">
        <el-input
          v-model="queryParams.customer"
          placeholder="请输入客户"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="产品编码" prop="productCode">
        <el-input
          v-model="queryParams.productCode"
          placeholder="请输入产品编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="产品名称" prop="productName">
        <el-input
          v-model="queryParams.productName"
          placeholder="请输入产品名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="产品类型" prop="productType">
        <el-select v-model="queryParams.productType" placeholder="请选择产品类型" clearable>
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>
      <el-form-item label="规格型号" prop="specificationModel">
        <el-input
          v-model="queryParams.specificationModel"
          placeholder="请输入规格型号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="单位" prop="unit">
        <el-input
          v-model="queryParams.unit"
          placeholder="请输入单位"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="单箱(pcs)数" prop="pcsPerBox">
        <el-input
          v-model="queryParams.pcsPerBox"
          placeholder="请输入单箱(pcs)数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="产品需求总数" prop="totalProductDemand">
        <el-input
          v-model="queryParams.totalProductDemand"
          placeholder="请输入产品需求总数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="订单类型" prop="orderType">
        <el-select v-model="queryParams.orderType" placeholder="请选择订单类型" clearable>
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>
      <el-form-item label="数据类型" prop="dataType">
        <el-select v-model="queryParams.dataType" placeholder="请选择数据类型" clearable>
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>
      <el-form-item label="包装报工数" prop="packagingReportQty">
        <el-input
          v-model="queryParams.packagingReportQty"
          placeholder="请输入包装报工数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="出库数量汇总" prop="outboundQuantitySummary">
        <el-input
          v-model="queryParams.outboundQuantitySummary"
          placeholder="请输入出库数量汇总"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="半/成品领用数量" prop="semiFinishedRequisitionQty">
        <el-input
          v-model="queryParams.semiFinishedRequisitionQty"
          placeholder="请输入半/成品领用数量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="领料人" prop="requisitioner">
        <el-input
          v-model="queryParams.requisitioner"
          placeholder="请输入领料人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="领料部门" prop="requisitionDept">
        <el-input
          v-model="queryParams.requisitionDept"
          placeholder="请输入领料部门"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="领料时间" prop="requisitionTime">
        <el-date-picker clearable
          v-model="queryParams.requisitionTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择领料时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="领料状态" prop="requisitionStatus">
        <el-select v-model="queryParams.requisitionStatus" placeholder="请选择领料状态" clearable>
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>
      <el-form-item label="主管确认状态" prop="supervisorConfirmStatus">
        <el-select v-model="queryParams.supervisorConfirmStatus" placeholder="请选择主管确认状态" clearable>
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>
      <el-form-item label="确认人" prop="confirmPerson">
        <el-input
          v-model="queryParams.confirmPerson"
          placeholder="请输入确认人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="确认时间" prop="confirmTime">
        <el-date-picker clearable
          v-model="queryParams.confirmTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择确认时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="创建人" prop="createdBy">
        <el-input
          v-model="queryParams.createdBy"
          placeholder="请输入创建人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建时间" prop="createdTime">
        <el-date-picker clearable
          v-model="queryParams.createdTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择创建时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="更新人" prop="updatedBy">
        <el-input
          v-model="queryParams.updatedBy"
          placeholder="请输入更新人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="更新时间" prop="updatedTime">
        <el-date-picker clearable
          v-model="queryParams.updatedTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择更新时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['mes:pro:requisition:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['mes:pro:requisition:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['mes:pro:requisition:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['mes:pro:requisition:export']"
        >导出</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-refresh"
          size="mini"
          @click="handleSync"
          v-hasPermi="['mes:pro:requisition:sync']"
        >数据同步</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="requisitionList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键ID" align="center" prop="id" />
      <el-table-column label="生产领料_id" align="center" prop="scllId" />
      <el-table-column label="生产领料单编号" align="center" prop="requisitionNo" />
      <el-table-column label="生产线" align="center" prop="productionLine" />
      <el-table-column label="生产类型" align="center" prop="productionType" />
      <el-table-column label="生产订单编号" align="center" prop="productionOrderNo" />
      <el-table-column label="订单日期" align="center" prop="orderDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.orderDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="客户" align="center" prop="customer" />
      <el-table-column label="产品编码" align="center" prop="productCode" />
      <el-table-column label="产品名称" align="center" prop="productName" />
      <el-table-column label="产品类型" align="center" prop="productType" />
      <el-table-column label="规格型号" align="center" prop="specificationModel" />
      <el-table-column label="单位" align="center" prop="unit" />
      <el-table-column label="单箱(pcs)数" align="center" prop="pcsPerBox" />
      <el-table-column label="产品需求总数" align="center" prop="totalProductDemand" />
      <el-table-column label="订单类型" align="center" prop="orderType" />
      <el-table-column label="数据类型" align="center" prop="dataType" />
      <el-table-column label="包装报工数" align="center" prop="packagingReportQty" />
      <el-table-column label="出库数量汇总" align="center" prop="outboundQuantitySummary" />
      <el-table-column label="半/成品领用数量" align="center" prop="semiFinishedRequisitionQty" />
      <el-table-column label="领料人" align="center" prop="requisitioner" />
      <el-table-column label="领料部门" align="center" prop="requisitionDept" />
      <el-table-column label="领料时间" align="center" prop="requisitionTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.requisitionTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="领料状态" align="center" prop="requisitionStatus" />
      <el-table-column label="备注" align="center" prop="requisitionRemark" />
      <el-table-column label="主管确认状态" align="center" prop="supervisorConfirmStatus" />
      <el-table-column label="确认人" align="center" prop="confirmPerson" />
      <el-table-column label="确认时间" align="center" prop="confirmTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.confirmTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="创建人" align="center" prop="createdBy" />
      <el-table-column label="创建时间" align="center" prop="createdTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createdTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="更新人" align="center" prop="updatedBy" />
      <el-table-column label="更新时间" align="center" prop="updatedTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updatedTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['mes:pro:requisition:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['mes:pro:requisition:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改生产领料单对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="生产领料_id" prop="scllId">
          <el-input v-model="form.scllId" placeholder="请输入生产领料_id" />
        </el-form-item>
        <el-form-item label="生产领料单编号" prop="requisitionNo">
          <el-input v-model="form.requisitionNo" placeholder="请输入生产领料单编号" />
        </el-form-item>
        <el-form-item label="生产线" prop="productionLine">
          <el-input v-model="form.productionLine" placeholder="请输入生产线" />
        </el-form-item>
        <el-form-item label="生产类型" prop="productionType">
          <el-select v-model="form.productionType" placeholder="请选择生产类型">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="生产订单编号" prop="productionOrderNo">
          <el-input v-model="form.productionOrderNo" placeholder="请输入生产订单编号" />
        </el-form-item>
        <el-form-item label="订单日期" prop="orderDate">
          <el-date-picker clearable
            v-model="form.orderDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择订单日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="客户" prop="customer">
          <el-input v-model="form.customer" placeholder="请输入客户" />
        </el-form-item>
        <el-form-item label="产品编码" prop="productCode">
          <el-input v-model="form.productCode" placeholder="请输入产品编码" />
        </el-form-item>
        <el-form-item label="产品名称" prop="productName">
          <el-input v-model="form.productName" placeholder="请输入产品名称" />
        </el-form-item>
        <el-form-item label="产品类型" prop="productType">
          <el-select v-model="form.productType" placeholder="请选择产品类型">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="规格型号" prop="specificationModel">
          <el-input v-model="form.specificationModel" placeholder="请输入规格型号" />
        </el-form-item>
        <el-form-item label="单位" prop="unit">
          <el-input v-model="form.unit" placeholder="请输入单位" />
        </el-form-item>
        <el-form-item label="单箱(pcs)数" prop="pcsPerBox">
          <el-input v-model="form.pcsPerBox" placeholder="请输入单箱(pcs)数" />
        </el-form-item>
        <el-form-item label="产品需求总数" prop="totalProductDemand">
          <el-input v-model="form.totalProductDemand" placeholder="请输入产品需求总数" />
        </el-form-item>
        <el-form-item label="订单类型" prop="orderType">
          <el-select v-model="form.orderType" placeholder="请选择订单类型">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="数据类型" prop="dataType">
          <el-select v-model="form.dataType" placeholder="请选择数据类型">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="包装报工数" prop="packagingReportQty">
          <el-input v-model="form.packagingReportQty" placeholder="请输入包装报工数" />
        </el-form-item>
        <el-form-item label="出库数量汇总" prop="outboundQuantitySummary">
          <el-input v-model="form.outboundQuantitySummary" placeholder="请输入出库数量汇总" />
        </el-form-item>
        <el-form-item label="半/成品领用数量" prop="semiFinishedRequisitionQty">
          <el-input v-model="form.semiFinishedRequisitionQty" placeholder="请输入半/成品领用数量" />
        </el-form-item>
        <el-form-item label="领料人" prop="requisitioner">
          <el-input v-model="form.requisitioner" placeholder="请输入领料人" />
        </el-form-item>
        <el-form-item label="领料部门" prop="requisitionDept">
          <el-input v-model="form.requisitionDept" placeholder="请输入领料部门" />
        </el-form-item>
        <el-form-item label="领料时间" prop="requisitionTime">
          <el-date-picker clearable
            v-model="form.requisitionTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择领料时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="领料状态">
          <el-radio-group v-model="form.requisitionStatus">
            <el-radio label="1">请选择字典生成</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="备注" prop="requisitionRemark">
          <el-input v-model="form.requisitionRemark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="主管确认状态">
          <el-radio-group v-model="form.supervisorConfirmStatus">
            <el-radio label="1">请选择字典生成</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="确认人" prop="confirmPerson">
          <el-input v-model="form.confirmPerson" placeholder="请输入确认人" />
        </el-form-item>
        <el-form-item label="确认时间" prop="confirmTime">
          <el-date-picker clearable
            v-model="form.confirmTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择确认时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="创建人" prop="createdBy">
          <el-input v-model="form.createdBy" placeholder="请输入创建人" />
        </el-form-item>
        <el-form-item label="创建时间" prop="createdTime">
          <el-date-picker clearable
            v-model="form.createdTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择创建时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="更新人" prop="updatedBy">
          <el-input v-model="form.updatedBy" placeholder="请输入更新人" />
        </el-form-item>
        <el-form-item label="更新时间" prop="updatedTime">
          <el-date-picker clearable
            v-model="form.updatedTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择更新时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="删除标识(0:未删除,1:已删除)" prop="delFlag">
          <el-input v-model="form.delFlag" placeholder="请输入删除标识(0:未删除,1:已删除)" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listRequisition, getRequisition, delRequisition, addRequisition, updateRequisition,requisitionListSync } from "@/api/mes/pro/requisition";

export default {
  name: "Requisition",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 生产领料单表格数据
      requisitionList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        scllId: null,        requisitionNo: null,        productionLine: null,        productionType: null,        productionOrderNo: null,        orderDate: null,        customer: null,        productCode: null,        productName: null,        productType: null,        specificationModel: null,        unit: null,        pcsPerBox: null,        totalProductDemand: null,        orderType: null,        dataType: null,        packagingReportQty: null,        outboundQuantitySummary: null,        semiFinishedRequisitionQty: null,        requisitioner: null,        requisitionDept: null,        requisitionTime: null,        requisitionStatus: null,        requisitionRemark: null,        supervisorConfirmStatus: null,        confirmPerson: null,        confirmTime: null,        createdBy: null,        createdTime: null,        updatedBy: null,        updatedTime: null,      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        requisitionNo: [
          { required: true, message: "生产领料单编号不能为空", trigger: "blur" }
        ],      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询生产领料单列表 */
    getList() {
      this.loading = true;
      listRequisition(this.queryParams).then(response => {
        this.requisitionList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,        scllId: null,        requisitionNo: null,        productionLine: null,        productionType: null,        productionOrderNo: null,        orderDate: null,        customer: null,        productCode: null,        productName: null,        productType: null,        specificationModel: null,        unit: null,        pcsPerBox: null,        totalProductDemand: null,        orderType: null,        dataType: null,        packagingReportQty: null,        outboundQuantitySummary: null,        semiFinishedRequisitionQty: null,        requisitioner: null,        requisitionDept: null,        requisitionTime: null,        requisitionStatus: "0",        requisitionRemark: null,        supervisorConfirmStatus: "0",        confirmPerson: null,        confirmTime: null,        createdBy: null,        createdTime: null,        updatedBy: null,        updatedTime: null,        delFlag: null      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加生产领料单";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getRequisition(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改生产领料单";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateRequisition(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addRequisition(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除生产领料单编号为"' + ids + '"的数据项？').then(function() {
        return delRequisition(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 数据同步按钮操作 */
    handleSync() {
      this.$modal.confirm('是否确认要同步数据').then(function() {
        return requisitionListSync();
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("数据同步成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('md/requisition/export', {
        ...this.queryParams
      }, `requisition_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
